
import 'package:sqflite/sqflite.dart';
import 'package:demo/DBBaseTest.dart';

class JDStorage {
  final Map<String, Database> dateBaseMap = {};

  static JDStorage? _instance;
  static JDStorage get instance => _getOrCreateInstance();
  static JDStorage _getOrCreateInstance() {
    if (_instance != null) {
      return _instance!;
    } else {
      _instance = JDStorage._();
      return _instance!;
    }
  }

  JDStorage._();
}

class JDStorageTool implements JDTableAction {
  ///数据库实例
  final Database database;
  JDStorageTool(this.database, String tableName, String sqlString) {
    noteDao = BaseTableAction(
        db: database, tableName: tableName, sqlString: sqlString);
  }
  BaseTableAction? noteDao;

  ///销毁数据库
  void destroy() {
    database?.close();
  }

  @override
  Future<List<DataModel>> getAllData() {
    return noteDao!.getAllData();
  }

  @override
  void saveData(DataModel model) {
    noteDao?.saveData(model);
  }

  @override
  void deleteData(int id) {
    noteDao?.deleteData(id);
  }

  @override
  Future<int> getDataCount() {
    return noteDao!.getDataCount();
  }

  @override
  void update(DataModel model) {
    noteDao?.update(model);
  }
}


